/*******************************************************************************
 * Copyright (c) 2010, 2030 www.mahao.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package cn.itlaobing.eshopmanagement.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/** 
 * ClassName: SessionController <br/> 
 * Function: TODO 功能描述 <br/> 
 * date: 2017年5月22日 上午11:46:46 <br/> 
 * 
 * @author Mmmmm 
 * @version  
 * @since JDK 1.8 
 */
@Controller
public class SessionController extends BaseController {

	public static final String CURRENT_ACCOUNT="currentAccount";
	
	@RequestMapping(value={"/index"})
	public String index(){
		return "index";
	}
	
	@RequestMapping(value={"/signin"},method=RequestMethod.GET)
	public String signin(){
		return "signin";
	}
	
	@RequestMapping(value={"/signin"},method=RequestMethod.POST)
	public String signin(String name,String password
			,HttpSession session
			,Model model){
		if(name.equals("admin") && password.equals("123456")) {
			session.setAttribute(CURRENT_ACCOUNT, name);
			return "redirect:/index";
		}
		model.addAttribute("toastMsg", "账号或密码错误");
		return "/signin";
	}
	
	@RequestMapping(value={"/signout"},method=RequestMethod.GET)
	public String signOut(HttpSession session){
		session.invalidate();
		return "redirect:signin";
	}
}
